package cn.tedu.rms.cart.controller;

import cn.tedu.rms.base.response.JsonResult;
import cn.tedu.rms.cart.pojo.dto.CartDeleteParam;
import cn.tedu.rms.cart.pojo.dto.CartQuery;
import cn.tedu.rms.cart.pojo.dto.CartSaveParam;
import cn.tedu.rms.cart.pojo.vo.CartVO;
import cn.tedu.rms.cart.service.CartService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@Api(tags = "购物车模块")
@RequestMapping("v1/cart")
public class CartController {
    @Autowired
    private CartService cartService;

    @PostMapping("insert")
    public JsonResult save(CartSaveParam cartSaveParam){
        //能自动将数值类(小数也可)型转为String,String形式的整数数字也能转为Long
        log.debug("保存记录到购物车，参数：{}",cartSaveParam);
        cartService.insertCart(cartSaveParam);
        return JsonResult.ok();
    }

    @PostMapping("deleteById/{id}")
    public JsonResult deleteById(@PathVariable Long id){
        log.debug("删除购物车记录，参数：{}",id);
        cartService.deleteCartById(id);
        return JsonResult.ok();
    }
    @PostMapping("deleteByIds")
    public JsonResult deleteById(CartDeleteParam cartDeleteParam){
        log.debug("批量删除购物车记录，参数：{}",cartDeleteParam);
        cartService.deleteCartByIds(cartDeleteParam);
        return JsonResult.ok();
    }
    @GetMapping("select")
    public JsonResult select(CartQuery cartQuery){
        log.debug("查询购物车记录，参数：{}",cartQuery);
        List<CartVO> cartVOSList = cartService.selectCart(cartQuery);
        return JsonResult.ok(cartVOSList);
    }


}
